
// app.js
App({
  globalData: {
    //域名
    host: 'http://api_devs.wanxikeji.cn',
    //设备信息
    navHeight: 0,
    navTop: 0,
    jnheight: 0,
    jnwidth: 0,
    openid:'',
    userInfo:'',
    windowHeight:''
  },
  /**
   * 当小程序初始化完成时，会触发 onLaunch（全局只触发一次）
   */
  onLaunch: function () {
    if(wx.getStorageSync('userInfo')){
      this.globalData.userInfo=wx.getStorageSync('userInfo')
    }
    if(wx.getStorageSync('openid')){
      this.globalData.openid=wx.getStorageSync('openid')
    }
    //获取系统信息
    this.getSystemInfo()
  },

  getSystemInfo() {
    //设置导航栏
    //获取菜单按钮的布局位置信息
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        //状态栏的高度
        let statusBarHeight = res.statusBarHeight,
          //胶囊按钮与顶部的距离
          navTop = menuButtonObject.top,
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
        this.globalData.windowHeight = res.windowHeight; //可使用高度
        this.globalData.navHeight = navHeight; //导航栏高度
        this.globalData.navTop = navTop; //胶囊按钮与顶部的距离
        this.globalData.jnheight = menuButtonObject.height; //胶囊的高度
        this.globalData.jnwidth = menuButtonObject.width; //胶囊的宽度
      },
      fail(err) {
        console.log(err);
      }
    });
  },
  /**
   * 当小程序启动，或从后台进入前台显示，会触发 onShow
   */
  onShow: function (options) {

  },

  /**
   * 当小程序从前台进入后台，会触发 onHide
   */
  onHide: function () {

  },

  /**
   * 当小程序发生脚本错误，或者 api 调用失败时，会触发 onError 并带上错误信息
   */
  onError: function (msg) {

  }
})